<script src="{{ getAssets }}js/ionRangeSlider/js/ion.rangeSlider.js" type="text/javascript"></script>
<script>
var sph_max = 0, sph_min = -8, sph_step = 0.25; //球径
var cyl_max = 0, cyl_min = 0, cyl_step = 0.25; //柱径
$("#range_1").ionRangeSlider({
    min: -30,
    max: 30,
    from: -8,
    to: 0,
    type: 'double',//设置类型
    step: 0.25,
    prefix: "",//设置数值前缀
    postfix: "",//设置数值后缀
    prettify: true,
    hasGrid: true,
    onFinish: function (opt) {
        sph_max = opt.toNumber;
        sph_min = opt.fromNumber;
    }
});
$("#range_2").ionRangeSlider({
    min: -8,
    max: 8,
    from: 0,
    to: 0,
    type: 'double',//设置类型
    step: 0.25,
    prefix: "",//设置数值前缀
    postfix: "",//设置数值后缀
    prettify: true,
    hasGrid: true,
    onFinish: function (opt) {
        cyl_max = opt.toNumber;
        cyl_min = opt.fromNumber;
    }
});
$("#formtable").validator({
    submit: function() {
        if(this.isFormValid()) {
            var TradePrice = $('#TradePrice').val();
            var SuggestedPrice = $('#SuggestedPrice').val();
            var CustomTradePrice = $('#CustomTradePrice').val();
            var CustomSuggestedPrice = $('#CustomSuggestedPrice').val();
            var DepartmentId = $('#DepartmentId').val();
            var product_id = $('#product_id').val();
            var price_id = $('#price_id').val();
            if(sph_max-sph_min<0){
                layer.alert("球镜所选范围不合理");
                return ;
            }else if(cyl_max-cyl_min<0){
                layer.alert("柱镜所选范围不合理");
                return ;
            }
            if((sph_min!=0&&sph_max!=0)&&(sph_min==sph_max)){
                layer.alert("球镜所选范围不合理");
                return ;
            }else if((cyl_min!=0&&cyl_max!=0)&&(cyl_min==cyl_max)){
                layer.alert("柱镜所选范围不合理");
                return ;
            }
            $.post('', {'product_id':product_id, 'price_id': price_id,'sph_max':sph_max,'sph_min':sph_min,'cyl_max':cyl_max, 'cyl_min':cyl_min ,'TradePrice':TradePrice, 'SuggestedPrice':SuggestedPrice,'CustomTradePrice':CustomTradePrice, 'CustomSuggestedPrice':CustomSuggestedPrice, 'DepartmentId':DepartmentId}, function(res){
                if(res.code == 1) {
                    layer.alert(res.msg);return false;
                }
                parent.layer.closeAll();
                parent.dialogReback();
            }, 'json');
        }
        return false;
    }
});
//设置门店列表
get_manage_departments(function (d) {
    var opt = [];
    if (d.length > 0) {
        opt.push('<option value="">请选择</option>');
        $.each(d, function (idx, val) {
            opt.push('<option value="' + val.Id + '">' + val.Name + '</option>');
        });
    }
    $('#DepartmentId').html(opt.join(''));
});
</script>